home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / GCC-2.3.3r12 / Tests / dash-b.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-09  |  1.1 KB  |  64 lines  |  [TEXT/MPS ]

  1. #include "testlib.h"
  2.  
  3. /* Compile with -b, each string should be 0-terminated. */
  4.  
  5. char *str1, *str2, *str3;
  6.  
  7. test_dash_b_1()
  8. {
  9.     str2 = "bazz";
  10.     str1 = "foo";
  11.     str3 = "bar";
  12.     itesteq(__LINE__, 0, str1[3]);
  13.     itesteq(__LINE__, 'z', str2[3]);
  14.     itesteq(__LINE__, 0, str2[4]);
  15. }
  16.  
  17. int fn(char *), fn2(char *);
  18.  
  19. test_dash_b_2()
  20. {
  21.     itesteq(__LINE__, 45, fn("goodbye"));
  22.     itesteq(__LINE__, 89, fn2("mundo"));
  23. }
  24.  
  25. /* Test handling of local static objects containing strings. */
  26.  
  27. struct smallstruct { char *key; int value; };
  28.  
  29. fn(char *str)
  30. {
  31.     int i;
  32.     static struct smallstruct stringlist[] =
  33.       { {"hello", 23}, {"goodbye", 45}, {"mundo", 89}};
  34.     
  35.     for (i = 0; i < 3; ++i) {
  36.         if (strcmp(str, stringlist[i].key) == 0) return stringlist[i].value;
  37.     }
  38.     return 0;
  39. }
  40.  
  41. int
  42. main()
  43. {
  44.     curtestfile = __FILE__;
  45.     test_dash_b_1();
  46.     test_dash_b_2();
  47.     summary();
  48.     return 0;
  49. }
  50.  
  51. #pragma segment seg2
  52.  
  53. fn2(char *str)
  54. {
  55.     int i;
  56.     static struct smallstruct stringlist[] =
  57.       { {"hello", 23}, {"goodbye", 45}, {"mundo", 89}};
  58.     
  59.     for (i = 0; i < 3; ++i) {
  60.         if (strcmp(str, stringlist[i].key) == 0) return stringlist[i].value;
  61.     }
  62.     return 0;
  63. }
  64.